package com.xxx.kjds.controller;


import com.xxx.kjds.entity.SaveGoods;
import com.xxx.kjds.entity.SaveGoodsKey;
import com.xxx.kjds.service.SaveGoodsService;
import com.xxx.kjds.service.StorehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/savegoods")
public class SaveGoodsController {

    @Autowired
    private com.xxx.kjds.service.SaveGoodsService SaveGoodsService;

    @Autowired
    private StorehouseService storehouseService;

    @PostMapping("/selectSaveGoodsByPrimaryKey")
    @ResponseBody
    public SaveGoods selectByPrimaryKey(Integer goodsID, Integer mvoID) {
        SaveGoodsKey key = new SaveGoodsKey(goodsID, mvoID);
        return SaveGoodsService.selectByPrimaryKey(key);
    }

    @PostMapping("/updateSaveGoodsByPrimaryKey")
    @ResponseBody
    public String updateByPrimaryKey(Integer goodsID, Integer storehouseID, int goodsNum) {
        SaveGoods record = new SaveGoods(goodsID, storehouseID, goodsNum);
        int re = SaveGoodsService.updateByPrimaryKey(record);
        if (re == 1) return "更新库存成功";
        return "更新库存失败";
    }

    @PostMapping("/insertSaveGoods")
    @ResponseBody
    public String insertSaveGoods(Integer goodsID, Integer storehouseID, int goodsNum) {
        SaveGoods record = new SaveGoods(goodsID, storehouseID, goodsNum);
        int re = SaveGoodsService.insert(record);
        if (re == 1) return "插入成功";
        return "插入有误";
    }


}
